package pactera.tf.mq;

import java.util.List;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;

import pactera.tf.controller.ChatWebSocketController;
import pactera.tf.dataobj.GroupChatMsgDO;

@Component
public class GroupChatMsgConsumer {
	
	@Autowired
	ChatWebSocketController chatWebSocketController;
	/**
	 * 
	
	 * <p>Title: receiveMessage</p>  
	
	 * <p>Description:消费单条消息 </p>  
	
	 * @param chatmsg
	 */
    @KafkaListener(topics = {"groupChatMsg"})
    public void receiveMessage(String chatmsg){
    	JSONObject jsonObject = JSONObject.parseObject(chatmsg);
        // 向指定群发送消息
    	chatWebSocketController.sendToAll(jsonObject.toJavaObject(GroupChatMsgDO.class));
        System.out.println(chatmsg);
    }
    
   

    /**
     * 
    
     * <p>Title: onMessage</p>  
    
     * <p>Description: 消费批量消息</p>  
    
     * @param crs
     */
    @KafkaListener(topics = "test")
    public void onMessage(List<String> crs) {
    }

    /**
     * 
    
     * <p>Title: consumer</p>  
    
     * <p>Description:读取消息的topic，offset，key，value等信息 </p>  
    
     * @param consumerRecord
     */
	@KafkaListener(topics = "test")
    public void consumer(ConsumerRecord consumerRecord){
    }
}
